Skip to main content
Inventory 4.0

Registering items

Define item properties and connect usable items to server exports.

Resource start order

Register all items inside the inventory resource. If another resource registers an item after the inventory loads, the item may not be added and may be deleted from an inventory.

Item definition

labelstring

Display name of the item.

tradableboolean

Controls whether the item can be traded.

deletableboolean

Controls whether the item can be deleted.

stackableboolean

Allows multiple items to share a stack.

descriptionstring

Item description.

weightnumber

Weight of one item.

categorystring

Category assigned to the item.

defaultMetaInventoryItemMetaData

Default metadata assigned to new items.

usableboolean

Controls whether the item can be used.

droppedModelstring

World model used when the item is dropped.

weaponHashnumber | string

Associated weapon hash.

allowedAttachmentsstring[]

Attachments supported by the item.

generateSerialboolean

Enables serial number generation.

server?{ export?: string; onUseDeleteAmount?: number }

Server export and removal amount used when the item is activated.

Register an item

Configuration

Basic item

Register money as a stackable, tradable currency item.

ScriptShared.Items:Add("money", {
stackable = true,
deletable = true,
tradable = true,
label = "Money",
weight = 0.0,
category = "Currency"
})

Register item use behavior

Set server.export to the export that should run when the item is used. Create that export in the named resource.

Configuration

Usable item

Register gold as a usable item connected to a server export.

ScriptShared.Items:Add("gold", {
stackable = true,
deletable = true,
tradable = true,
label = "Gold",
weight = 1.5,
usable = true,
category = "Raw material",
server = {
export = "resource_name.any_function_name",
onUseDeleteAmount = 1
}
})
Configuration

Item use export

Handle the item in the resource specified by server.export.

exports("any_function_name", function(source, item)
print(source)
print(json.encode(item, { indent = true }))
end)